package com.atelier.plugin.projectWizard;

import com.atelier.plugin.projectWizard.data.DataSetting;
import com.atelier.plugin.projectWizard.data.ProjectConfig;
import com.atelier.plugin.projectWizard.ui.ProjectSetting;
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.options.ConfigurationException;

import javax.swing.*;

/**
 * @author tangrufei
 * @date 2023-05-17 11:16
 */
public class HywayModuleConfigStep extends ModuleWizardStep implements Disposable
{
    private ProjectSetting projectSettingUi;


    @Override
    public JComponent getComponent() {
        return projectSettingUi.getMainJpanel();
    }
    public HywayModuleConfigStep(ProjectSetting projectSetting){
        this.projectSettingUi=projectSetting;
    }
    @Override
    public void updateDataModel() {
    }

    @Override
    public boolean validate() throws ConfigurationException {
         ProjectConfig state = DataSetting.getInstance().getState();
         state.setName(projectSettingUi.getName().getText());
         state.setGroup(projectSettingUi.getGroup().getText());
         state.setPackageName(projectSettingUi.getPackageName().getText());
         state.setArtifactId(projectSettingUi.getArtifact().getText());
         state.setVersion(projectSettingUi.getVersion().getText());
         state.setProjectBaseDir(projectSettingUi.getLocationBrowseButton().getText());
         System.out.println(state);
         Boolean b = projectSettingUi.validateFields();
        System.out.println(b);
        System.out.println("validate");
        return b;
    }

    /**
     * Usually not invoked directly, see class javadoc.
     */
    @Override
    public void dispose()
    {

    }
}
